﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

using CNVP.Framework.Utils;
using CNVP.Config;

namespace CNVP.JShop.Web.Member
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            DateTime time = DateTime.Now.AddHours(1);
            string userName = this.txtUserName.Text.Trim();
            string userpwd = this.txtUserPwd.Text.Trim();
            if (string.IsNullOrEmpty(userName))
            {
                MessageUtils.ShowPre("用户名称不能为空！");
                return;
            }
            if (string.IsNullOrEmpty(userpwd))
            {
                MessageUtils.ShowPre("用户密码不能为空！");
                return;
            }
            BLL.CNVP_Users bll = new BLL.CNVP_Users();
            Model.CNVP_Users model = new Model.CNVP_Users();
            model.UserName = userName;
            model.UserPass = EncryptUtils.MD5(userpwd);
            model.IsDelete = 0;
            model = bll.cust_LoginByName(model);
            if (model != null)
            {
                Response.Cookies["" + UIConfig.CookiesName + "UserID"].Value = EncryptUtils.EncodeCookies(model.ID.ToString());
                Response.Cookies["" + UIConfig.CookiesName + "UserName"].Value = EncryptUtils.EncodeCookies(model.UserName);
                Response.Cookies["" + UIConfig.CookiesName + "UserLevelID"].Value = EncryptUtils.EncodeCookies(model.UserLevelID.ToString());
                //更新
                //更新
                model.EndLoginIP = HttpContext.Current.Request.UserHostAddress;
                model.EndLoginTime = DateTime.Now.AddMinutes(1);
                bll.cust_UpdateLogin(model);
                string _url = Request.QueryString["URL"];
                if (!string.IsNullOrEmpty(_url))
                {
                    _url = _url.Replace("|", "&");
                    Response.Redirect(_url, false);
                }
                else
                {
                    Response.Redirect("/member/AdvanceAds.aspx", false);
                }
            }
            else
            {
                MessageUtils.ShowPre("对不起!你的账号密码有误!或者您没有注册！");
            }
        }

    }
}
